package ws.jdbc.concurrent.driver.sqlserver;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import ws.performancetest.api.TestSuite;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class CDriver implements Driver {

  private final int MINOR_VERSION = 0;
  private final int MAJOR_VERSION = 0;
  protected static final String subProtocol = "jdbc:sqlserver:";

  static {
    try {
      DriverManager.registerDriver(new CDriver());
    } catch (SQLException ex) {
      Logger.getLogger(CDriver.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

  /**
   * {@inheritDoc}
   */
  public Connection connect(String url, Properties info) throws SQLException {
    if (!this.acceptsURL(url)) {
      return null;
    } else {
      return new CConnection(url, info);
    }
  }

  /**
   *
   * The general form of the connection URL is
   *  jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
   *
   * @param url
   * @return
   * @throws SQLException
   */
  public boolean acceptsURL(String url) throws SQLException {
    if (url == null) {
      return false;
    }

    return url.toLowerCase().startsWith(subProtocol);
  }

  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public int getMajorVersion() {
    return MAJOR_VERSION;
  }

  public int getMinorVersion() {
    return MINOR_VERSION;
  }

  public boolean jdbcCompliant() {
    return false;
  }
}
